<?php
//Google Map Auto
add_shortcode('bbmap', 'gt_google_map');
function gt_google_map( $atts, $content = null ) {
	global $post;
    extract(shortcode_atts(array(
		'zoom' => '12',
		'height' => '300',
		'layout' => 'fullwidth',
		'align' => 'center',
		'description' => '',
    ), $atts));
	
	//enqueue shortcode script
	wp_enqueue_script( 'google_map','http://maps.google.com/maps/api/js?sensor=false' );
	
	$latitude = get_post_meta($post->ID, '_'.$post->post_type.'_latitude', true);
	$longitude = get_post_meta($post->ID, '_'.$post->post_type.'_longitude', true);
	
	//output map
	$out='<div class="google-map-container align-'.$align.'"><div class="google-map" id="google-map" style="height:'.$height.'px"></div><input type="hidden" class="map-latitude" value="'.$latitude.'" />';
	$out.='<input type="hidden" class="map-longitude" value="'.$longitude.'" /><input type="hidden" class="map-zoom" value="'.$zoom.'" /><input type="hidden" class="map-description" value="'.$description.'" /></div>';
	
	if($layout=='fullwidth') {
		$out='<div class="clear"></div></div></div>'.$out.'<div class="container content"><div class="row">';
	}
   
    return $out;
}

//Tours
add_shortcode('bbtours','gt_tours');
function gt_tours( $atts, $content = null ) {
	extract(shortcode_atts(array(
		'number' => '4',
		'columns' => '4',
		'order' => 'date',
		'type' => '0',
		'destination' => '0',
    ), $atts));
	
	global $post;
	
	$query = new WP_Query(array(
		'post_type' => 'tour',
		'showposts' => intval($number),
		'orderby' => $order,
		'meta_key'    => '_thumbnail_id',
	));	
	
	$layout='three';
	switch($columns) {
		case '3': $layout='four'; break;
		case '4': $layout='three'; break;
	}	
	
	$out='<div class="items-grid">';
	$counter=0;
	if ($query->have_posts()) : while ( $query->have_posts() ) : $query->the_post();
		$counter++;
		$destinations=themex_category($post->ID, 'destination');
		$price=themex_price($post->ID);
		
		$out.='<div class="'.$layout.'col column ';
		if($counter==intval($columns)) {
			$out.='last';			
		}		
		
		$out.='"><div class="tour-thumb-container"><div class="tour-thumb">';
		$out.='<a href="'.get_permalink().'"><img class="fullwidth" src="'.themex_thumbnail($post->ID,460).'" alt="'.get_the_title().'" /></a>';
		$out.='<div class="tour-caption"><h5 class="tour-title"><a href="'.get_permalink().'">'.get_the_title().'</a></h5>';
		
		if($destinations!='' || $price!='') {
			$out.='<div class="tour-meta">';
			if($destinations!='') {
				$out.='<div class="tour-destination"><div class="colored-icon icon-2"></div>'.$destinations.'</div>';
			}
			if($price!='') {
				$out.='<div class="tour-duration">'.$price.'</div><div class="clear"></div></div>';
			}
		}
		
		$out.='</div></div><div class="block-background"></div></div></div>';
		if($counter==intval($columns)) {
			$out.='<div class="clear"></div>';
			$counter=0;			
		}
	endwhile;
	endif;
	wp_reset_query();
	$out.='<div class="clear"></div></div><div class="clear"></div>';
	return $out;
}

//Testimonials
add_shortcode('bbtestimonials','gt_testimonials');
function gt_testimonials( $atts, $content = null ) {
	global $post;
	extract(shortcode_atts(array(
		'pause' => '0',
		'speed' => '400',
		'number' => '-1',
		'order' => 'date'
    ), $atts));
	$query = new WP_Query(array(
		'post_type' => 'testimonial',
		'orderby' => $order,
		'meta_query' => array(
			array(
				'key' => '_testimonial_tour',
				'value' => $post->ID
			)
		),
		'showposts' => intval($number),
	));
	$out='<div class="fade-slider testimonials-slider"><ul>';
	if ($query->have_posts()) : while ( $query->have_posts() ) : $query->the_post();
		$out.='<li><div class="quote"><div class="block-background">'.get_the_content().'</div></div><h6 class="quote-author">'.get_post_meta($post->ID,'_testimonial_author',true).'</h6></li>';
	endwhile;
	endif;
	wp_reset_query();
	$out.='</ul><input type="hidden" class="slider-pause" value="'.$pause.'" />';
	$out.='<input type="hidden" class="slider-speed" value="'.$speed.'" />';
	$out.='<input type="hidden" class="slider-effect" value="fade" /></div>';
	return $out;
}

?>